package com.iemp.config.consts;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class FileTransferSettingEntryConsts {

    public static final String TRANSFER_UPLOAD_FOLDER = "transfer.upload.folder";
    public static final String TRANSFER_DOWNLOAD_PREFIX = "transfer.download.prefix";

    private static Map<String, String> map = new HashMap<>();
    private static boolean unloaded = true;

    public static Map<String, String> map() throws IllegalAccessException {
        Class<?> clazz = FileTransferSettingEntryConsts.class;
        Field[] fields = clazz.getDeclaredFields();
        Map<String, String> ret = new HashMap<>();
        for (Field field : fields) {
            String fieldName = field.getName();
            if ("map".equals(fieldName) || "unloaded".equals(fieldName)) {
                continue;
            }
            Object o = field.get(null);
            ret.put(fieldName, (String) o);
        }
        return ret;
    }

    public static String map(String key) throws IllegalAccessException {
        if (unloaded) {
            map = map();
        }
        return map.get(key);
    }
}
